package com.xiaoxu.yihaoShop.ProvenceJob;

import com.xiaoxu.utils.LogParser;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.Map;

public class ProvenceMapper extends Mapper<LongWritable, Text,Text,LongWritable> {

    private LogParser logParser;

    private LongWritable ONE = new LongWritable(1);

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        logParser = new LogParser();
    }

    //58.219.82.109	中国	江苏省	无锡市
    // 3T489Y1W6TECTAKDFFTYMQUEH2EW5GG6	2013-07-21 13:57:11	-
    // http://www.yihaodian.com/5/?tracker_u=2225501&type=4
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        Map<String, String> logInfo = logParser.parseAfterETL(value.toString());

        String province = logInfo.get("province");


        context.write(new Text(province),ONE);
    }
}
